package Hot100;

import LinkedList.ListNode;

public class 删除链表的倒数第N个节点 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        int i = -1;
        ListNode dummyNode = new ListNode();
        dummyNode.next = head;
        ListNode curr = dummyNode;
        while (head != null) {
            head = head.next;
            i++;
            if (i >= n) curr = curr.next;
        }
        curr.next = curr.next.next;
        return dummyNode.next;
    }
}
